<template>
  <div class="AdendDialog">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="16">
          <el-form-item label="流程名称" prop="name">
            <el-input v-model="ruleForm.name" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="关键字" prop="Keyword">
            <el-input v-model="ruleForm.Keyword" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="URL" prop="url">
            <el-input v-model="ruleForm.url" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="事件Bean" prop="method">
            <el-input v-model="ruleForm.method" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="分类ID" prop="type">
            <el-input v-model="ruleForm.type" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="生效日期" prop="time">
            <el-date-picker v-model="ruleForm.time" type="date" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="描述" prop="message">
            <el-input type="textarea" autosize placeholder="请输入内容" v-model="ruleForm.message">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {
      close: {
        type: Function,
        default: null,
      },
      jobyin: {
        type: Function,
        default: null
      },
      changeText: {
        type: Function,
        default: null
      }
    },
    data() {
      return {
        ruleForm: {
          name: "",
          Keyword: "",
          url: "",
          method: "",
          type: '',
          time: '',
          message: ''
        },
        value1: '',
        textarea1: '',
        rules: {
          name: [{
            required: true,
            message: "请输入名称",
            trigger: "blur",
          }, ],
          Keyword: [{
            required: true,
            message: "请输入关键字",
            trigger: "blur",
          }, ],
          url: [{
            required: true,
            message: "请输入url",
            trigger: "blur",
          }, ],
          method: [{
            required: true,
            message: "请输入事件Bean",
            trigger: "blur",
          }, ],
          type: [{
            required: true,
            message: "请输入分类id",
            trigger: "blur",
          }, ],
          time: [{
            required: true,
            message: "请选择生效日期",
            trigger: "blur",
          }, ],
          message: [{
            required: true,
            message: "请输入描述",
            trigger: "blur",
          }]
        }
      }
    },
    methods: {
      // 表单提交
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$server.enginesubmit(this.ruleForm).then((res) => {
              this.$message({
                type: "success",
                message: "添加成功!",
              });
              this.changeText('工作流引擎')
              this.jobyin()
              // 关闭弹框
              this.close();
              for (let object in this.ruleForm) {
                this.ruleForm[object] = ''
              }
            });
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.close();
      },
    }
  }
</script>

<style>
</style>
